<?php
/**
 +---------------------------------------<br/>
 * 控制器:首页导航<br/>
 +---------------------------------------
 * @category membership
 * @package web.front.action
 * @author skygreen skygreen2001@gmail.com
 */
class Action_Auth extends Action
{
    //登录
    public function login(){
        $this->loadCss("resources/css/msg.css");
        $this->loadCss("resources/css/login.css");
        $this->loadJs("js/msg.js");
        $this->loadJs("js/login.js");
        $this->view->set("site_name","会员登录");
    }

    public function ajaxlogin(){
        $username = isset($_POST['username'])?$_POST['username']:"";
        $password = isset($_POST['password'])?$_POST['password']:"";
        $data = array("username"=>$username,"password"=>$password);
        $result = UtilApi::store_login($data);
        if ($result->code == "A00006") {
            $store = $result->data;
            if ($store->store_id) {
                if ($result->key) {
                    HttpSession::set("ApiKey",$result->key);
                    HttpSession::set("sbs_id",$store->sbs_id);
                    HttpSession::set("userid",$store->user_id);
                    HttpSession::set("store_id",$store->store_id);
                    $response = array(
                        "success" => "success",
                        "data" => "登录成功",
                        "url" => "index.php?go=softpos.index.entry"
                    );
                }else{
                   $response = array(
                        "success" => "no",
                        "data" => "请为该门店的商户生成api密钥",
                        "url" => ""
                    );
                }
            }else{
               $response = array(
                    "success" => "no",
                    "data" => "请用门店用户登录",
                    "url" => ""
                ); 
            }
            
        } else {
            $response = array(
                "success" => "no",
                "data" => $result->result,
                "url" => ""
            );
        }
        echo json_encode($response);
        exit;
    }

    public function logout(){
        HttpSession::remove("userid");
        HttpSession::remove("store_id");
        $this->redirect("auth", "login");
    }
}
?>